def selectionsort(arr):
    if len(arr) <= 1:
        return arr
    
    n = len(arr)
    for i in range(n):
        i_min = i  # the position of the min of the remaining array
        for j in range(i+1, n):
            if arr[j] < arr[i_min]:
                i_min = j
        arr[i], arr[i_min] = arr[i_min], arr[i]  # swap
    
    return arr


if __name__ == "__main__":
    print(selectionsort([9, 2, 8]))
    print(selectionsort([3, 6, 0, 4]))
    print(selectionsort([1, 8, 7, 3, 6, 0, 4]))
